package acwing_05;
import java.util.*;
import java.io.*;
public class _908_线性DP_最短编辑距离 {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static StringTokenizer st;
	static int N = 1010;
	static int n,m;
	static String A,B;
	static char[] a = new char[N];
	static char[] b = new char[N];
	static int[][] dp = new int[N][N];
	public static void main(String[] args) throws IOException{
		n = Integer.parseInt(br.readLine());
		A = br.readLine();
		m = Integer.parseInt(br.readLine());
		B = br.readLine();
		
		for(int i = 1; i <= n; i++) {
			a[i] = A.charAt(i-1);
		}
		for(int j = 1; j <= m; j++) {
			b[j] = B.charAt(j-1);
		}
		  
		// 初始化dp
		for(int i = 0; i <= n; i++) {
			dp[i][0] = i;
		}
		for(int i = 0; i <= m; i++) {
			dp[0][i] = i;
		}
		
		for(int i = 1; i <= n; i++) {
			for(int j = 1; j <= m; j++) {
				dp[i][j] = Math.min(dp[i-1][j] + 1, dp[i][j-1] + 1);
				if(a[i] == b[j]) {
					dp[i][j] = Math.min(dp[i][j], dp[i-1][j-1]);
				}else {
					dp[i][j] = Math.min(dp[i][j], dp[i-1][j-1] + 1);
				}
			}
		}
		System.out.println(dp[n][m]);
	}
}
